<?php
class Upload_artwork extends Controller
{
	function __construct()
	{
		parent::__construct();	
	}
	
	function index()
	{
        $this->load->helper(array('form', 'url'));
		
		$this->load->library('form_validation');
        $this->form_validation->set_error_delimiters('<div class="error">','</div>');
        
        //this->form_val;idation->set_rules(exact form field name,name that will be displayed in error message,rules)
        $this->form_validation->set_rules('fullname','full name','callback_fullname_check');
        $this->form_validation->set_rules('company','company name','callback_company_check');
        $this->form_validation->set_rules('telephone','contact number','callback_telephone_check');
        $this->form_validation->set_rules('email','email address','required|valid_email');
        $this->form_validation->set_rules('jobname','job name or number','callback_jobname_check');
        $this->form_validation->set_rules('cenumber','cost estimate number','callback_cenumber_check');
        $this->form_validation->set_rules('quantity','quantity','required|numeric');
        $this->form_validation->set_rules('deadline','date and time','callback_deadline_check');
        
        $this->form_validation->set_message('required','Please enter your %s');
        $this->form_validation->set_message('numeric','Please enter %s number only');
        $this->form_validation->set_message('valid_email', 'Please enter valid  %s');
				
		if ($this->form_validation->run() == FALSE)
		{
			$this->load->view(TEMPLATE_NAME.'/front/upload_artwork/upload_artwork_view');
		}
		else
		{
            $this->load->model('upload_artwork_model');	
            $insert_id=$this->upload_artwork_model->insert();
			
			//$this->upload_artwork_model->update_artworkfiles($insert_id);
            
             //send email to the admin as well as the client who submits the artwork
             $this->upload_artwork_model->send_upload_email_admin($insert_id);//send email to admin
             $this->upload_artwork_model->send_upload_email_client($insert_id);//send email to the client
             
            $this->load->view(TEMPLATE_NAME.'/front/upload_artwork/upload_artwork_success');
		}
	}
    
    function fullname_check($str)
    {
        if($str=='your name' || $str=='')
        {
            $this->form_validation->set_message('fullname_check','Please enter your %s');
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }
    
    function company_check($str)
    {
        if($str=='your company name' || $str=='')
        {
            $this->form_validation->set_message('company_check','Please enter your %s');
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }
    
    function telephone_check($str)
    {
        if($str=='your contact number' || $str=='')
        {
            $this->form_validation->set_message('telephone_check','Please enter your %s');
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }
      
    function jobname_check($str)
    {
        if($str=='your job name or number' || $str=='')
        {
            $this->form_validation->set_message('jobname_check','Please enter your %s');
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }
    
    function cenumber_check($str)
    {
        if($str=='your cost estimate number' || $str=='')
        {
            $this->form_validation->set_message('cenumber_check','Please enter your %s');
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }
    
    function deadline_check($str)
    {
        if($str=='select a date and time'|| $str=='')
        {
            $this->form_validation->set_message('deadline_check','Please select a %s');
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }
    
}
?>